//
// Created by Administrator on 2023/11/21.
//
#include "bits/stdc++.h"

using namespace std;


struct ListNode {
    int val;
    ListNode *next;

    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode *filterList(ListNode *head) {
        bool st[10005] = {};
        auto p = head;
        while (p) {
            int val=abs(p->val);
            st[val]= true;

            auto q=p->next;
            if(q==NULL) break;
            val=abs(q->val);

            while(st[val]){
                q=q->next;
                if(q==NULL) break;
                val=abs(q->val);
            }
            p->next=q;
            p=p->next;

        }
        return head;
    }
};
